<template>
    <el-dialog
            :title="!dataForm.performanceId ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="绩效考核ID，主键" prop="performanceId">
                        <el-input v-model.number="dataForm.performanceId" placeholder="绩效考核ID，主键"></el-input>
                </el-form-item>
                <el-form-item label="审计人员ID，对应审计人员信息表" prop="personnelId">
                        <el-input v-model.number="dataForm.personnelId" placeholder="审计人员ID，对应审计人员信息表"></el-input>
                </el-form-item>
                <el-form-item label="考核周期（如2023年第一季度）" prop="assessmentPeriod">
                        <el-input v-model="dataForm.assessmentPeriod" placeholder="考核周期（如2023年第一季度）"></el-input>
                </el-form-item>
                <el-form-item label="工作质量得分" prop="workQualityScore">
                        <el-input v-model.number="dataForm.workQualityScore" placeholder="工作质量得分"></el-input>
                </el-form-item>
                <el-form-item label="工作效率得分" prop="workEfficiencyScore">
                        <el-input v-model.number="dataForm.workEfficiencyScore" placeholder="工作效率得分"></el-input>
                </el-form-item>
                <el-form-item label="工作态度得分" prop="workAttitudeScore">
                        <el-input v-model.number="dataForm.workAttitudeScore" placeholder="工作态度得分"></el-input>
                </el-form-item>
                <el-form-item label="团队协作得分" prop="teamCollaborationScore">
                        <el-input v-model.number="dataForm.teamCollaborationScore" placeholder="团队协作得分"></el-input>
                </el-form-item>
                <el-form-item label="综合绩效评价（如优秀、良好、合格、不合格）" prop="overallPerformance">
                        <el-input v-model="dataForm.overallPerformance" placeholder="综合绩效评价（如优秀、良好、合格、不合格）"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            performanceId: null,
            personnelId: null,
            assessmentPeriod: null,
            workQualityScore: null,
            workEfficiencyScore: null,
            workAttitudeScore: null,
            teamCollaborationScore: null,
            overallPerformance: null
          },
          dataRule: {
            performanceId: [
                        { required: true, message: '绩效考核ID，主键不能为空', trigger: 'blur' }
            ],
            personnelId: [
                        { required: true, message: '审计人员ID，对应审计人员信息表不能为空', trigger: 'blur' }
            ],
            assessmentPeriod: [
                        { required: true, message: '考核周期（如2023年第一季度）不能为空', trigger: 'blur' }
            ],
            workQualityScore: [
                        { required: true, message: '工作质量得分不能为空', trigger: 'blur' }
            ],
            workEfficiencyScore: [
                        { required: true, message: '工作效率得分不能为空', trigger: 'blur' }
            ],
            workAttitudeScore: [
                        { required: true, message: '工作态度得分不能为空', trigger: 'blur' }
            ],
            teamCollaborationScore: [
                        { required: true, message: '团队协作得分不能为空', trigger: 'blur' }
            ],
            overallPerformance: [
                        { required: true, message: '综合绩效评价（如优秀、良好、合格、不合格）不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      methods: {
        init (id) {
          this.dataForm.performanceId = id || 0
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.dataForm.performanceId = id || 0
            if (this.dataForm.performanceId) {
              this.$http({
                url: this.$http.adornUrl(`/app/audit_performance/info/${this.dataForm.performanceId}`),
                method: 'get',
                params: this.$http.adornParams()
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.dataForm = data.appauditperformance
                }
              })
            }
          })
        },
            // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
              this.$http({
                url: this.$http.adornUrl(`/app/audit_performance/${!this.dataForm.performanceId ? 'save' : 'update'}`),
                method: 'post',
                data: this.$http.adornData(this.dataForm)
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            }
          })
        }
      }
    }
</script>